
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <title>
        个人设置
    </title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" th:href="@{/css/main.css}" media="all">
    <style>
        .imgs{display: none;}
        input[type="file"]{
            width: 50px;
            height:50px;
            border-radius: 100%;
            opacity:0;
            cursor:pointer;
            border: 1px solid red;
            position: absolute;
        }
    </style>

</head>
<body>

<div class="x-body">
    <form class="layui-form layui-form-pane" action="" id="add">
        <blockquote class="layui-elem-quote">
            <input type="hidden" name="id" th:value="${a.id}">
            <div >
                <input class="layui-upload " type="file" accept="undefined" id="previewImg"  onchange="upload(this,8)">
                <img th:src="@{${a.admin_pic}}" class="layui-circle" style="width:50px;height:50px;float:left" id="pimages"    alt="个人头像" >
                <input id="avatar"   required="" type="hidden" value="./images/tx.jpg" >
                <dl style="margin-left:80px; color:#019688">
                    <dt><span th:text="${a.login_code}">ADMIN</span> <span ></span></dt>
                    <dd style="margin-left:0" th:text="${a.infor}"></dd>
                </dl>
            </div>
        </blockquote>

        <div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">


            <div class="layui-tab-content" >
                <div class="layui-tab-item layui-show">


                    <div class="layui-form-item">
                        <label class="layui-form-label">
                            <span class='x-red'>*</span>用户名
                        </label>
                        <div class="layui-input-block">
                            <input type="text"  name="login_code" autocomplete="off" placeholder="空制在80个汉字，160个字符以内"
                                   class="layui-input" value="ADMIN" th:value="${a.login_code}">
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <label for="name" class="layui-form-label">
                            <span class="x-red">*</span>姓名
                        </label>
                        <div class="layui-input-inline">
                            <input type="text" id="name" name="name" required="" lay-verify="required"
                                   autocomplete="off" class="layui-input" value="" th:value="${a.name}">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label for="email" class="layui-form-label">
                            <span class="x-red">*</span>邮箱
                        </label>
                        <div class="layui-input-inline">
                            <input type="text" id="email" name="email" required="" lay-verify="email"
                                   autocomplete="off" class="layui-input" value="" th:value="${a.email}">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">
                            <span class='x-red'>*</span>电话号码
                        </label>
                        <div class="layui-input-block">
                            <input type="text" name="phone"  autocomplete="off" placeholder=""
                                   class="layui-input"  value="" th:value="${a.phone}">
                        </div>
                    </div>

                    <div class="layui-form-item layui-form-text">
                        <label class="layui-form-label">
                            <span class='x-red'>*</span>描述
                        </label>
                        <div class="layui-input-block">
                            <textarea  th:text="${a.infor}" name="infor" class="layui-textarea"></textarea>
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <label class="layui-form-label">
                            <span class='x-red'>*</span>密码
                        </label>
                        <div class="layui-input-block">
                            <input type="password"  value="" autocomplete="off" placeholder="" id="password"
                                   class="layui-input" lay-verify="pwd">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">
                            <span class='x-red'>*</span>新密码
                        </label>
                        <div class="layui-input-block">
                            <input type="password" name="password" id="newpassword" value="" autocomplete="off" placeholder="新密码为空则不修改"
                                   class="layui-input"  lay-verify="newpassword">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">
                            <span class='x-red'>*</span>确认新密码
                        </label>
                        <div class="layui-input-block">
                            <input type="password" name="re_newpassword" id="re_newpassword" value="" autocomplete="off" placeholder="新密码为空则不修改"
                                   class="layui-input" lay-verify="re_newpassword">
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <button class="layui-btn" type="button" lay-filter="add" lay-submit="">
                            保存
                        </button>
                    </div>
                    <!--</form>-->
                    <div style="height:100px;"></div>
                </div>



            </div>

        </div>
    </form>
</div>
<script th:src="@{/lib/layui/layui.js}" charset="utf-8"></script>
<script th:src="@{/js/x-layui.js}" charset="utf-8"></script>
<!--<script th:src="@{/js/jquery-2.2.4.min.js}" charset="utf-8"></script>-->
<script>

</script>
<script>
    layui.use(['element','layer','form'], function(){
        $ = layui.jquery;//jquery
        lement = layui.element();//面包导航
        layer = layui.layer;//弹出层
        form = layui.form();

        $("#password").blur(function(){
            var password = $('#password').val();
            $.ajax({
                type:"post",
                url:"/administrator/checkPwd",
                data:{password:password},
                dataType:"json",
                success:function (data) {
                    if (data.status==0){
                        layer.msg(data.msg,{icon: 6,time:1000});
                        $('#password').focus();
                    }
                }
            });
        })

        form.verify({
            login_code: function(value){
                if(value.length < 5){
                    return '登录名至少得5个字符啊';
                }
            }
            ,newpassword: [/(.+){6,12}$/, '密码必须6到12位']
            ,re: function(value){
                if($('#newpassword').val()!=$('#re_newpassword').val()){
                    return '两次密码不一致';
                }
            }
        });


        //监听提交
        form.on('submit(add)', function(data){
            var name=$("input[name='name']").val();

            if(name==""){
                layer.msg('用户名不能为空',{icon:5,time:2000});return false;
            }

            var data=data.field;
            console.log(data);
            alert(data.data);
            // var login_code = $('#login_code').val();
            // var phone = $('#phone').val();

            $.ajax({
                type:"post",
                url:"/administrator/editAdmin",
                data:data,
                dataType:"json",
                success:function(data)
                {
                    //alert(1);
                    if(data.status==1)
                    {
                        layer.msg(data.msg, {icon: 6,time:2000},function () {
                            window.parent.location.reload();
                            var index = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(index);
                        });
                        return false;

                    }
                    else{
                        layer.msg(data.msg,{icon:5,time:2000});return false;
                    }
                }

            });

        });

    })
</script>
<!--栏目缩略图上传-->
<script>
    function upload(obj,id){
        var formData = new FormData();
        formData.append('images', $('#previewImg')[0].files[0]);
        formData.append('id', id);
        layer.msg('图片上传中', {icon: 16});
        $.ajax({
            type:"post",
            processData: false,
            contentType: false,
            url:"xxx",
            data:formData,
            success:function(data){
                if(data.status == 1){
                    console.log(data.image_name);
                    layer.closeAll('loading');
                    //layer.msg(data.info,{icon:1,time:1000});
                    $("#pimages").attr('src',data.image_name);
                    $("#avatar").val(data.image_name);
                    $(".imgs").show();
                    return false;
                }else{
                    layer.msg(data.info,{icon:2,time:1000});
                }
            }
        });
    }
</script>

</body>
</html>